package edu.cuc.chap02.lianxi.l2.Client;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class TimeClientHandlerl2 extends ChannelInboundHandlerAdapter{
    private  ByteBuf byteBuf;
    public TimeClientHandlerl2() {
        String request = "QUERY TIME ORDER";
        byte[] bytes = request.getBytes();
        byteBuf = Unpooled.buffer(request.length());
        byteBuf.writeBytes(bytes);
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        ctx.writeAndFlush(byteBuf);
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf byteBuf = (ByteBuf) msg;
        byte[] bytes = new byte[byteBuf.readableBytes()];
        byteBuf.readBytes(bytes);
        String resp = new String(bytes);
        System.out.println(resp);

    }
}
